package com.right.health.app.ui.me.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.magic.basic.adapter.BaseAbsAdapter;
import com.magic.basic.utils.DateFormatUtil;
import com.right.health.app.R;
import com.right.health.app.bean.ServiceItemBean;
import com.right.health.app.bean.ServicePackResponse;

import java.util.Date;

/**
 * @author: weming
 * @date: 2021/4/24
 * @description:
 */
public class ServiceItemAdapter extends BaseAbsAdapter<ServiceItemBean> {

    private boolean isOrder;
    private View.OnClickListener mClickListener;

    public ServiceItemAdapter(Context context) {
        super(context);
    }

    public void setOrder(boolean order) {
        isOrder = order;
    }

    public void setClickListener(View.OnClickListener clickListener) {
        mClickListener = clickListener;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_my_service, null);
            viewHolder = new ViewHolder();
            viewHolder.mTimeTv = convertView.findViewById(R.id.tv_time);
            viewHolder.mTitleTv = convertView.findViewById(R.id.tv_title);
            viewHolder.mStateTv = convertView.findViewById(R.id.tv_state);
            viewHolder.mCompleteTv = convertView.findViewById(R.id.tv_complete);
            if (mClickListener!=null)
                viewHolder.mCompleteTv.setOnClickListener(mClickListener);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        ServiceItemBean bean = getDataSource().get(position);
        if (!isOrder) {
            viewHolder.mTimeTv.setVisibility(View.GONE);
            viewHolder.mCompleteTv.setVisibility(View.GONE);
            viewHolder.mStateTv.setVisibility(View.GONE);
        }else {
            viewHolder.mTimeTv.setVisibility(View.VISIBLE);
            viewHolder.mCompleteTv.setVisibility(View.VISIBLE);
            viewHolder.mStateTv.setVisibility(View.VISIBLE);
            viewHolder.mTimeTv.setText("预约时间："+ DateFormatUtil.formatDate(new Date(bean.getMaketime()),"yyyy-MM-dd HH:mm"));
            if (bean.getIsfinish().equals("1")) {
                viewHolder.mStateTv.setText("已完成");
                viewHolder.mCompleteTv.setBackgroundResource(R.drawable.shape_cancel_btn1);
            }else {
                viewHolder.mStateTv.setText("未完成");
                viewHolder.mCompleteTv.setBackgroundResource(R.drawable.selector_login_btn);
            }
        }
        viewHolder.mCompleteTv.setTag(position);
        viewHolder.mTitleTv.setText(bean.getItemname()+":\n"+bean.getContent());

        return convertView;
    }

    static class ViewHolder {
        private TextView mTitleTv, mTimeTv,mStateTv,mCompleteTv;
    }
}
